//
//  myVC.m
//  CMAccountBook
//
//  Created by 王开政 on 2018/10/30.
//  Copyright © 2018年 王开政. All rights reserved.
//

#import "myVC.h"
#import "settingVC.h"
#import "systematicManagementVC.h"
#import "inviteFriendsVC.h"
#import "deblockingVC.h"
#import "billStatisticsVC.h"
#import "regularlyRemindVC.h"
@interface myVC ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic, strong) UITableView *Tab;

@property(nonatomic, strong) UIView *headView;

@property(nonatomic,strong)UILabel *name;
@property(nonatomic,strong)UILabel *content;
@property(nonatomic,strong)UIImageView *photoImage;

@property(nonatomic,strong)UILabel *runningDays;

@property(nonatomic,strong)UILabel *runningDaysLabel;

@property(nonatomic,strong)UILabel *totalDays;

@property(nonatomic,strong)UILabel *totalDaysLabel;

@property(nonatomic,strong)UILabel *allAccount;

@property(nonatomic,strong)UILabel *allAccountLabel;

@property (nonatomic, retain) UISwitch *switchButton;

@end

@implementation myVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    self.navigationController.navigationBarHidden=YES;
    [self.view addSubview:self.Tab];
    // Do any additional setup after loading the view.
}
//防止左划卡顿问题
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}

-(void)viewWillDisappear:(BOOL)animated
{
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    [super viewWillDisappear:animated];
}
-(UIView *)headView{
    if (!_headView) {
        _headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, SafeAreaTopHeight + 165*kfit)];
        _headView.backgroundColor = [UIColor whiteColor];
        [_headView addSubview:self.name];
        [_headView addSubview:self.content];
        [_headView addSubview:self.photoImage];
        
        [_headView addSubview:self.runningDays];
        [_headView addSubview:self.runningDaysLabel];
        [_headView addSubview:self.totalDays];
        
        [_headView addSubview:self.totalDaysLabel];
        [_headView addSubview:self.allAccount];
        [_headView addSubview:self.allAccountLabel];
    }
    return _headView;
}
-(UILabel *)name{
    
    if (!_name) {
        _name = [[UILabel alloc]initWithFrame:CGRectMake(20*kfit,SafeAreaTopHeight, ScreenWidth-120*kfit, 20*kfit)];
        //        self.name.backgroundColor = [UIColor orangeColor];
        _name.textColor = [UIColor colorWithHexString:@"#101010"];
        _name.text = @"遗失的痛";
        //        _name.textAlignment = NSTextAlignmentCenter;
        _name.font = [UIFont systemFontOfSize:18*kfit];
        
    }
    
    return _name;
}
-(UILabel *)content{
    
    if (!_content) {
        _content = [[UILabel alloc]initWithFrame:CGRectMake(20*kfit,SafeAreaTopHeight+40*kfit, ScreenWidth-120*kfit, 20*kfit)];
        //        self.name.backgroundColor = [UIColor orangeColor];
        _content.textColor = [UIColor colorWithHexString:@"#8a8a8a"];
        _content.text = @"哪有什么岁月静好，只是有人替你负重前行";
        //        _content.textAlignment = NSTextAlignmentCenter;
        _content.font = [UIFont systemFontOfSize:13*kfit];
        
    }
    
    return _content;
}
-(UIImageView *)photoImage{
    
    if (!_photoImage) {
        
        _photoImage = [[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth-80*kfit,SafeAreaTopHeight+0*kfit,60*kfit, 60*kfit)];
        _photoImage.layer.cornerRadius = 60*kfit*0.5;
        _photoImage.layer.masksToBounds = YES;
        _photoImage.image = [UIImage imageNamed:@"PersonalHead"];
        //        UIView *photoBG = [[UIView alloc]initWithFrame:<#(CGRect)#>]
        
        
    }
    
    return _photoImage;
}
-(UILabel *)runningDays{
    
    if (!_runningDays) {
        _runningDays = [[UILabel alloc]initWithFrame:CGRectMake(0*kfit,SafeAreaTopHeight+100*kfit, ScreenWidth/3, 25*kfit)];
        //        self.name.backgroundColor = [UIColor orangeColor];
        _runningDays.textColor = [UIColor colorWithHexString:@"#101010"];
        _runningDays.text = @"10";
        _runningDays.textAlignment = NSTextAlignmentCenter;
        _runningDays.font = [UIFont systemFontOfSize:18*kfit];
        
    }
    
    return _runningDays;
}
-(UILabel *)totalDays{
    
    if (!_totalDays) {
        _totalDays = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth/3,SafeAreaTopHeight+100*kfit, ScreenWidth/3, 25*kfit)];
        //        self.name.backgroundColor = [UIColor orangeColor];
        _totalDays.textColor = [UIColor colorWithHexString:@"#101010"];
        _totalDays.text = @"8";
        _totalDays.textAlignment = NSTextAlignmentCenter;
        _totalDays.font = [UIFont systemFontOfSize:18*kfit];
        
    }
    
    return _totalDays;
}
-(UILabel *)allAccount{
    
    if (!_allAccount) {
        _allAccount = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth *2/3,SafeAreaTopHeight+100*kfit, ScreenWidth/3, 25*kfit)];
        //        self.name.backgroundColor = [UIColor orangeColor];
        _allAccount.textColor = [UIColor colorWithHexString:@"#101010"];
        _allAccount.text = @"12";
        _allAccount.textAlignment = NSTextAlignmentCenter;
        _allAccount.font = [UIFont systemFontOfSize:18*kfit];
        
    }
    
    return _allAccount;
}
-(UILabel *)runningDaysLabel{
    
    if (!_runningDaysLabel) {
        _runningDaysLabel = [[UILabel alloc]initWithFrame:CGRectMake(0,SafeAreaTopHeight+131*kfit, ScreenWidth/3, 25*kfit)];
        //        self.name.backgroundColor = [UIColor orangeColor];
        _runningDaysLabel.textColor = [UIColor colorWithHexString:@"#8a8a8a"];
        _runningDaysLabel.text = @"已连续记账";
        _runningDaysLabel.textAlignment = NSTextAlignmentCenter;
        _runningDaysLabel.font = [UIFont systemFontOfSize:12*kfit];
        
    }
    
    return _runningDaysLabel;
}
-(UILabel *)totalDaysLabel{
    
    if (!_totalDaysLabel) {
        _totalDaysLabel = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth/3,SafeAreaTopHeight+131*kfit, ScreenWidth/3, 25*kfit)];
        //        self.name.backgroundColor = [UIColor orangeColor];
        _totalDaysLabel.textColor = [UIColor colorWithHexString:@"#8a8a8a"];
        _totalDaysLabel.text = @"记账总天数";
        _totalDaysLabel.textAlignment = NSTextAlignmentCenter;
        _totalDaysLabel.font = [UIFont systemFontOfSize:12*kfit];
        
    }
    
    return _totalDaysLabel;
}
-(UILabel *)allAccountLabel{
    
    if (!_allAccountLabel) {
        _allAccountLabel = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth*2/3,SafeAreaTopHeight+131*kfit, ScreenWidth/3, 25*kfit)];
        //        self.name.backgroundColor = [UIColor orangeColor];
        _allAccountLabel.textColor = [UIColor colorWithHexString:@"#8a8a8a"];
        _allAccountLabel.text = @"记账总笔数";
        _allAccountLabel.textAlignment = NSTextAlignmentCenter;
        _allAccountLabel.font = [UIFont systemFontOfSize:12*kfit];
        
    }
    
    return _allAccountLabel;
}
-(UISwitch *)switchButton{
    if (!_switchButton) {
        _switchButton = [[UISwitch alloc]initWithFrame:CGRectMake(ScreenWidth- 80*kfit, 10*kfit, 30*kfit, 20*kfit)];
        
        //缩小或者放大switch的size
        _switchButton.transform = CGAffineTransformMakeScale(1*kfit, 1*kfit);
        _switchButton.layer.anchorPoint = CGPointMake(0, 0.3);
        [_switchButton addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
        
    }
    return _switchButton;
}
-(void)switchAction:(UISwitch *)sender{
    if (sender.isOn) {
    }else{
    }
    NSLog(@"%d",sender.isOn);
}
-(UITableView *)Tab{
    
    if (!_Tab) {
        _Tab = [[UITableView alloc]initWithFrame:CGRectMake(0,0, ScreenWidth, ScreenHeight)];
        _Tab.backgroundColor = [UIColor colorWithHexString:@"#f5f5f5"];
        _Tab.delegate = self;
        _Tab.dataSource = self;
        //        self.myTab.scrollEnabled = NO;
        _Tab.showsVerticalScrollIndicator = NO;
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 50)];
        UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, ScreenWidth, 40)];
        lab.text = @"阿里云提供数据安全保障";
        lab.font = [UIFont systemFontOfSize:14*kfit];
        lab.textColor = [UIColor colorWithHexString:@"#999999"];
        lab.textAlignment = NSTextAlignmentCenter;
        [view addSubview:lab];
        //        _Tab.tableFooterView = view;
        _Tab.tableHeaderView = self.headView;
        _Tab.tableFooterView.backgroundColor = [UIColor colorWithHexString:@"#f5f5f5"];
        if(@available(iOS 11.0, *)){
            _Tab.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            _Tab.estimatedRowHeight = 0;
            _Tab.estimatedSectionHeaderHeight = 0;
            _Tab.estimatedSectionFooterHeight = 0;
            
        }
        
    }
    
    return _Tab;
}
#pragma mark -设置cell横线左顶边
-(void)viewDidLayoutSubviews {
    if ([self.Tab respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.Tab setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([self.Tab respondsToSelector:@selector(setLayoutMargins:)])  {
        [self.Tab setLayoutMargins:UIEdgeInsetsZero];
    }
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPat{
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
}
#pragma  make - UITableViewDataSource

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 2;
}



-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (section == 0) {
        return 4;
    }
    return 3;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    
    if (!cell) {
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
        
    }
    cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            cell.textLabel.text = @"分类管理";
        }else if (indexPath.row == 1){
            cell.textLabel.text = @"定时提醒";
        }else if (indexPath.row == 2){
            cell.textLabel.text = @"账单统计";
        }else if (indexPath.row == 3){
            cell.textLabel.text = @"解锁密码";
        }
    }else if (indexPath.section == 1){
        if (indexPath.row == 0) {
            cell.accessoryType =UITableViewCellAccessoryNone;
            cell.textLabel.text = @"声音开关";
            [cell addSubview:self.switchButton];
        }else if (indexPath.row == 1){
            cell.textLabel.text = @"邀请好友";
        }else if (indexPath.row == 2){
            cell.textLabel.text = @"设置";
        }
    }
    return cell;
}

#pragma  make - UITableViewDelegate
//返回高度，计算不同高度cell 一定要用，否则会出现偏移
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    return 60;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view =[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 10)];
    view.backgroundColor = [UIColor colorWithHexString:@"#F6F6F8"];
//    UILabel *leftLabel = [[UILabel alloc]initWithFrame:CGRectMake(21*kfit, 0, ScreenWidth/2, 35)];
//    leftLabel.textColor = [UIColor colorWithHexString:@"#B7B7B7"];
//    leftLabel.font = [UIFont systemFontOfSize:10*kfit];
//    leftLabel.textAlignment = NSTextAlignmentLeft;
//    leftLabel.text =self.sectionArray[section][@"data"];
//
//    UILabel *rightLabel = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth/2 -21*kfit, 0, ScreenWidth/2, 35)];
//    rightLabel.textColor = [UIColor colorWithHexString:@"#B7B7B7"];
//    rightLabel.font = [UIFont systemFontOfSize:10*kfit];
//    rightLabel.textAlignment = NSTextAlignmentRight;
//    rightLabel.text =self.sectionArray[section][@"money"];
//
//    [view addSubview:leftLabel];
//    [view addSubview:rightLabel];
    
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0.01;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            
            systematicManagementVC *VC = [[systematicManagementVC alloc]init];
            self.navigationController.navigationBarHidden=NO;
            [VC setHidesBottomBarWhenPushed:YES];
            [self.navigationController pushViewController:VC animated:YES];
            
        }else if (indexPath.row == 1){
            
            regularlyRemindVC *VC = [[regularlyRemindVC alloc]init];
            self.navigationController.navigationBarHidden=NO;
            [VC setHidesBottomBarWhenPushed:YES];
            [self.navigationController pushViewController:VC animated:YES];
        }else if (indexPath.row == 2){
            
            billStatisticsVC *VC = [[billStatisticsVC alloc]init];
            self.navigationController.navigationBarHidden=NO;
            [VC setHidesBottomBarWhenPushed:YES];
            [self.navigationController pushViewController:VC animated:YES];
        }else if (indexPath.row == 3){
          
            deblockingVC *VC = [[deblockingVC alloc]init];
            self.navigationController.navigationBarHidden=NO;
            [VC setHidesBottomBarWhenPushed:YES];
            [self.navigationController pushViewController:VC animated:YES];
        }
    }else if (indexPath.section == 1){
        if (indexPath.row == 0) {
           
            
        }else if (indexPath.row == 1){
            inviteFriendsVC *VC = [[inviteFriendsVC alloc]init];
            self.navigationController.navigationBarHidden=NO;
            [VC setHidesBottomBarWhenPushed:YES];
            [self.navigationController pushViewController:VC animated:YES];

        }else if (indexPath.row == 2){
            settingVC *VC = [[settingVC alloc]init];
            self.navigationController.navigationBarHidden=NO;
            [VC setHidesBottomBarWhenPushed:YES];
            [self.navigationController pushViewController:VC animated:YES];
        }
    }
   
    
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
